package com.demo.security.token.authenticated;

import org.springframework.security.authentication.AbstractAuthenticationToken;

import java.util.Date;

/**
 * 经过验证后的token
 * when a jwt is authenticated, return this
 * @author molong
 * @since 2024/5/23
 */
public class AuthenticatedToken extends AbstractAuthenticationToken {

    /**
     * 主体
     */

    private final Object principal;

    /**
     * 过期时间
     */
    private Date expiration;


    public AuthenticatedToken(String principal, Date expiration) {
        super(null);
        this.principal = principal;
        this.expiration = expiration;
        //已经通过验证
        setAuthenticated(true);
    }

    public AuthenticatedToken(Object principal) {
        super(null);
        this.principal = principal;
    }

    @Override
    public boolean isAuthenticated() {
        return super.isAuthenticated();
    }

    public Date getExpiration() {
        return expiration;
    }

    @Override
    public Object getCredentials() {
        return null;
    }

    @Override
    public Object getPrincipal() {
        return principal;
    }
}
